package org.java8newfeature.stream;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ComparatorDemo {
    public static void main(String[] args) throws Exception {
        Employee e1 = new Employee(1, 23, "M", "Rick", "Beethovan");
        Employee e2 = new Employee(2, 13, "F", "Martina", "Hengis");
        Employee e3 = new Employee(3, 43, "M", "Ricky", "Martin");
        Employee e4 = new Employee(4, 26, "M", "Jon", "Lowman");
        Employee e5 = new Employee(5, 19, "F", "Cristine", "Maria");
        Employee e6 = new Employee(6, 15, "M", "David", "Feezor");
        Employee e7 = new Employee(7, 68, "F", "Melissa", "Roy");
        Employee e8 = new Employee(8, 79, "M", "Alex", "Gussin");
        Employee e9 = new Employee(9, 15, "F", "Neetu", "Singh");
        Employee e10 = new Employee(10, 45, "M", "Naveen", "Jain");


        List<Employee> employees = Arrays.asList(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10);

        // TODO: 2024/7/5 一下两种相等 一种是lambda 一种是方法引用
        Function<Employee, Integer> f = employee -> employee.getAge();
        Function<Employee, Integer> reference = Employee::getAge;


        Comparator<Employee> comparing = Comparator.comparing(Employee::getAge);
        Comparator<Employee> c = (a, b) -> a.getAge() - b.getAge();
        Comparator<Employee> d = (a, b) -> Integer.compare(a.getAge(), b.getAge());
        List<String> collect = employees.stream().sorted(Comparator.comparing(Employee::getAge)).map(Employee::getFirstName).collect(Collectors.toList());

    }
}
